package com.bodacn.keypoint.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bodacn.keypoint.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ClothPieceSearchGrAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context mContext;
    private List<String> list;
    private int selectIndex;

    public ClothPieceSearchGrAdapter(List<String> list, Context context, int selectIndex) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.list = list;
        this.selectIndex=selectIndex;
    }


    public void setSelectIndex(int selectIndex){
        this.selectIndex=selectIndex;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHodler;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_cloth_piece_gr, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
        viewHodler.tvPartName.setText(list.get(position));
//        if (selectIndex>-1&&selectIndex==position) {
//            convertView.setSelected(true);
//            convertView.setFocusable(true);
//        }
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.tv_PartName)
        TextView tvPartName;
        @BindView(R.id.mylistitem)
        LinearLayout mylistitem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


}
